#-*- codeing = uft-8 -*-
#@Time :2021/9/4 19:46
#@AUTHOR :07杜照选
#@file : spiderApple.py
#@Software: PyCharm
import requests
import re
import time
url = "https://www.apple.com.cn/"
head = {"user-agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"}
response = requests.get(url,headers = head)
page = response.text
patt = r'background-image: url(.*?.jpg)'
com = re.compile(patt,re.M|re.S)
sea = re.findall(com,response.text)
print(sea)
http = "https://www.apple.com.cn/"
list = []
for img in sea:
     link = img.replace("(\"",'')
     # time.sleep(1)
     URL = http+link
     # print(URL)
     list.append(URL)
num = 1
for i in list:
    new = requests.get(i)
    with open('E:\HTML软件\学习软件\Apple官网\images\%d.jpg'%num,'wb') as f:
        f.write(new.content)
        print("%d image has been downloaded"%(num))
    num += 1



